﻿/*****************************************************
 * 本类库的核心系 JNTemplate
 * (C) JNTemplate 2011
 * 作者：翅膀的初衷 QQ:4585839
 * 网址：http://www.JiNianNet.com
 *****************************************************/
using System;
using System.Text.RegularExpressions;

namespace JinianNet.JNTemplate.Process
{
    #region 解析正则表达式
    internal static class ParserRegex
    {
        private static readonly RegexOptions options;
        ///// <summary>
        ///// 循环标签
        ///// </summary>
        //internal static readonly Regex ForeachRegex;
        /// <summary>
        /// 变量标签
        /// </summary>
        internal static readonly Regex VariableRegex;
        ///// <summary>
        ///// 方法标签
        ///// </summary>
        //internal static readonly Regex FunctaionRegex;
        ///// <summary>
        ///// 引用标签
        ///// </summary>
        //internal static readonly Regex IncludeRegex;
        ///// <summary>
        ///// For循环标签
        ///// </summary>
        //internal static readonly Regex ForRegex;

        //internal static readonly Regex IfRegex;

        //internal static readonly Regex ElseIfRegex;

        /// <summary>
        /// 是否数字
        /// </summary>
        internal static readonly Regex Number;
        /// <summary>
        /// 是否小数
        /// </summary>
        internal static readonly Regex Double;

        internal static readonly Regex Judge;

        static ParserRegex()
        {
            
            #region 初始化表达式
            options = RegexOptions.IgnoreCase| RegexOptions.Compiled;

            VariableRegex = new Regex("^\\s*[a-zA-Z]{1}\\w*(\\[\"\\w+\"\\]|\\[\\w+\\])*(\\.\\w+(\\[\\w+\\]|\\[\"\\w+\"\\])*)*\\s*$", options);
            //ForeachRegex = new Regex(@"^\s*\#foreach *\( *(?<Entity>\w+) +in +(?<Source>[\s\S]+) *\)\s*$", options);
            //FunctaionRegex = new Regex(@"^\s*(\[(?<Method>[\w\.]+)\])?(?<Key>[\w\.]+)\((?<Parameter>[\S ]*)\)\s*$", options);
            //IncludeRegex = new Regex("<!--#include\\s+file=\"(?<Path>[^\"]+?)\"\\s*-->|<!--#include\\s+file=\"(?<Path>[^\"]+?)\"\\s*charset=\"(?<Charset>[^\"]+?)\"\\s*-->", options);
            //ForRegex = new Regex(@"^\s*\#for\((?<Var>[a-zA-Z]{1}\w*)\=(?<Start>[\w\.\[\]]+);\k<Var>(?<Determine>\>|\<|\=\=|\>\=|\<\={1})(?<End>[\w\.\[\]]+);\k<Var>(((?<Calculate>[\+\-\*\/]{1})\=(?<Step>[\w\.\[\]]+))|(?<Calculate>[\+\-]{2}))\)$", options);
            //IfRegex = new Regex(@"^\s*\#if *\( *(?<Parameter>[\s\S]+) *\)\s*$", options);
            //ElseIfRegex = new Regex(@"^\s*\#else *if *\( *(?<Parameter>[\s\S]+) *\)\s*$", options);
            Number = new Regex(@"^-?\d+$", options);
            Double = new Regex(@"^-?\d+\.?\d*$", options);
            Judge = new Regex("^(?<X>(\"[\\s\\S]*\")|([A-Za-z]{1}[\\w\\.\\[\\]\"]*)|([\\d]+[\\.]?[\\d]*)) *(?<Equals>\\>|\\>\\=|\\<\\=|\\<|\\=\\=|\\!\\=) *(?<Y>(\"[\\s\\S]*\")|([A-Za-z]{1}[\\w\\.\\[\\]\"]*)|([\\d]+[\\.]?[\\d]*))$", options);
            #endregion
        }
    }
    #endregion
}
